<?php
error_reporting(0);
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es" dir="ltr">
  <head>
    <!--  metas de JL {{ -->
    <title>Catalogo de venta de laptops y mini laptops</title>
    <meta name="description" content="Catalogo de laptops, portátiles y mini laptops más grande de Venezuela"/>
    <meta name="keywords" content="Catalogo de laptop, portatiles y mini laptop, "/>
    <!--  }} metas de JL  -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="default.css" />
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.tools.min.js"></script>
  </head>
  <body>
<?php
  include_once("fachadaBD.php");
  include("top_1-06-2011.php");
  include("left.php");
  $f = new fachadaBD();
  $marcas = $f->obtenerMarcas($_GET["marca"]);
  $lprocesadores = $f->obtenerMarcaTecnologia();
  $procesadores ="";
  $esta = false;
  while ($row=mysql_fetch_array($lprocesadores)) {
    $id=$row["MARCA"]." ".$row["NOMBRE"];
    if ($_GET["procesador"] == $row["NOMBRE"]){
      $procesadores.= "<option selected value=\"".$row["NOMBRE"]."\">".$id."</option>";
      $esta = true;
    } else
      $procesadores.= "<option value=\"".$row["NOMBRE"]."\">".$id."</option>";
  }
  if ($esta)
    $procesadores.="<option value=\"\">Todas</option>";
  else
    $procesadores.="<option selected value=\"\">Todas</option>";
  $f->cerrar();
  function div($row,$marcaTec){
    ?>
    <div id= "contenido" style="width: 100%;">
      <table align="left">
        <td style="padding-left: 2px;">
          <a href="<?php echo "especificacion.php?modelo=".$row["MODELO"];?>">
            <img style="border: 0px" align="center" src = "<?php echo $row["IMAGENGRANDE"]?>">
          </a>
        </td>
        <td>
        <table>
          <tr>
            <td>
              <span class="sub">
                <?php echo $row["MARCA"]." ".$row["MODELO"] ?>
              </span>
              <span class="sub2">
                <?php
                  echo $marcaTec." ".$row["VELOZPROC"]." GHz, "
                .$row["MEMORIA"]." GB RAM, ".$row["DISCO"]." GB disco duro"
                .", Pantalla ".$row["PANTALLA"].", ".$row["SISTEMA"];
                  if ($row["HD_MI"] == 1){
                    echo ", HDMI";
                  }
                  if ($row["BLUETOOTH"] == 1){
                    echo ", Bluetooth";
                  }
                ?>
                <br>
              </span>
            </td>
          </tr>
          <tr>
            <td style="font-size: 11px;font-family: Arial;">
               <?php echo $row["DESCRIPCION"]; ?>
            </td>
          </tr>
          <tr>
            <td style="font-size: 17px;">
              <br>
              <form action="IniciarCompra.php" method="POST">
                <?php echo "Bs:".$row["PRECIO"]; ?>
                <input type="hidden" name="modelo" value="<?echo $row["MODELO"]; ?>">
                <input type="hidden" name="cantidad" value="1">
                <input type="image" 
                       style="border: 0px;"
                       onmouseover="src='images/comprar-2.jpg'"
                       onmouseout="src='images/COMPRAR_BOTON.jpg'"
                       alt="Comprar" src="images/COMPRAR_BOTON.jpg">
                <a href="<?php echo "especificacion.php?modelo=".$row["MODELO"];?>">
                  <img alt="Informacion"
                       style="border: 0px;"
                       onmouseover="src='images/info-3.jpg'"
                       onmouseout="src='images/BOTON_LISTO.jpg'"
                       src="images/BOTON_LISTO.jpg">
                </a>
              </form>
            </td>
          </tr>
          <tr>
            <td>
              <span style="font-size: 9px;">
                <b>(incluye IVA)</b>
              </span>
              <div style="text-align: right;color: #990000;">
                <?php echo $row["GARANTIA"]?>
              </div>
            </td>
          </tr>
        </table>
      </td>
    <td width=120><img src="images/catalogo/detalles.jpg"></td>
    </table>
  </div>
<?php
  }
  function opciones_ver($num){
    $opc = array("15","20","25");
    for ($i = 0; $i < 3; $i++){
      if ($num == $opc[$i]){
        echo "<option selected VALLUE=\"".$opc[$i]."\">".$opc[$i]."</option>";
      }else{
        echo "<option VALLUE=\"".$opc[$i]."\">".$opc[$i]."</option>";
      }
    }
  }
?>
	<div id="contentC" style="width: 780px;">
    <form name = "catalogo" action="catalogo.php" method="GET">
      <div id= "contenido" style="width: 100%; border: 3px solid #FED443;">
        <font class="Myriad Pro" style="padding-left: 20px;" size="7" color="#EF7100">
          <b><I>Busca tu Laptop</I></b>
        </font>
        <br>
        <p style="padding-left: 20px">
          Elige las caracter&iacute;sticas de tu Laptop
        </p>
          <br>
        <div class="sCata" style="padding-left: 20px; padding-right: 50px;">
          <table style="height: 137px; padding-left: 25px">
            <tr>
              <td>Tipo de Equipo</td>
              <td><SELECT name="tipo">
                  <?php if ($_GET["tipo"] == 1){ ?>
                    <option selected VALUE=1>Laptop</option>
                  <?php } else{?>
                    <option VALUE=1>Laptop</option>
                  <?php } if ($_GET["tipo"] == 2){?>
                    <option selected VALUE=2>Minilaptop</option>
                  <?php } else{?>
                    <option VALUE=2>Minilaptop</option>
                  <?php } if ($_GET["tipo"] == 0){ ?>
                    <option selected VALUE=0>Todos</option>
                  <?php } else{?>
                    <option VALUE=0>Todos</option>
                  <?php } ?>
                </SELECT></td>
            </tr>
            <tr>
              <td>Marca</td>
              <td><SELECT name="marca" >
                  <?=$marcas?>
                </SELECT></td>
            </tr>
            <tr>
              <td>Procesador</td>
              <td><SELECT name="procesador" style="width: 100px">
                  <?=$procesadores?>
                </SELECT></td>
            </tr>
            <tr>
              <td>Precio</td>
              <td style="padding-left: 5px;"><select size="1" name="precio">
                  <?php if ($_GET["precio"] == ""){ ?>
                    <option selected value="">Todas</option>
                  <?php } else { ?>
                      <option value="">Todas</option>
                   <?php
                   } if ($_GET["precio"] == "<=2999") { ?>
                     <option selected  value="<=2999">Menos de Bs. 2.999</option>
                   <?php } else { ?>
                     <option  value="<=2999">Menos de Bs. 2.999</option>
                  <?php } if ($_GET["precio"] == ">=3000 AND PRECIO<=3999"){ ?>
                     <option selected  value=">=3000 AND PRECIO<=3999">
                       Entre Bs. 3.000 - 3.999
                     </option>
                  <?php  } else { ?>
                     <option  value=">=3000 AND PRECIO<=3999">
                       Entre Bs. 3.000 - 3.999
                     </option>
                  <?php } if ($_GET["precio"] == ">=4000 AND PRECIO<=4999"){ ?>
                     <option  selected value=">=4000 AND PRECIO<=4999">
                       Entre Bs. 4.000 - 4.999
                     </option>
                  <?php  } else { ?>
                     <option  value=">=4000 AND PRECIO<=4999">
                       Entre Bs. 4.000 - 4.999
                     </option>
                  <?php } if ($_GET["precio"] == ">=5000 AND PRECIO<=5999"){ ?>
                     <option selected value=">=5000 AND PRECIO<=5999">
                       Entre Bs. 5.000 - 5.999
                     </option>
                  <?php  } else { ?>
                     <option value=">=5000 AND PRECIO<=5999">Entre Bs. 5.000 - 5.999</option>
                  <?php } if ($_GET["precio"] == ">=6000"){ ?>
                     <option selected value=">=6000">
                       M&aacute;s de Bs. 6.000
                     </option>
                  <?php  } else { ?>
                     <option  value=">=6000">M&aacute;s de Bs. 6.000</option>
                  <?php }?>
                </select></td>
            </tr>
          </table>
        </div>
<!--    <div class="catalogo_menuR" style="float: left;">-->
        <div class="sCata">
          <table style="height: 137px; padding-left: 25px">
            <tr>
              <td>Memoria Ram </td>
              <td><SELECT name="min" >
                  <?php
                    if($_GET["min"] == ""){
                      echo "<option selected >Todas</option>";
                    }else{
                      echo "<option>Todas</option>";
                    }
                    for ($i = 1; $i < 6; $i++){
                      if ($i == 5){
                        if ($_GET["min"] == $i){
                          echo "<option selected value=\"".$i."\">mas de 4 GB</option>";
                        }else{
                          echo "<option value=\"".$i."\">mas de 4 GB</option>";
                        }
                      }else{
                        if ($_GET["min"] == $i){
                          echo "<option selected value=\"".$i."\">".$i." GB</option>";
                        }else{
                          echo "<option value=\"".$i."\">".$i." GB</option>";
                        }
                      }
                    }
                  ?>
                </SELECT></td>
            </tr>
            <tr>
              <td>Disco duro </td>
              <td style="padding-left: 5px;"><SELECT name="discomin" >
                  <?php
                    $amin = array( "",
                            "0 AND DISCO<=80",
                            "81 AND DISCO<=120",
                            "121 AND DISCO<=320",
                            "321 AND DISCO<=500",
                            "501 AND DISCO<=999",
                            "1000");
                    $val = array ("Todos",
                           "menos de 80 GB",
                           "entre 81 y 120 GB",
                           "entre 121 y 320 GB",
                           "entre 321 y 500 GB",
                           "entre 501 y 999 GB",
                           "M&aacute;s de un 1 TB");
                    for ($i = 0; $i < 7;$i++){
                       if ($_GET["discomin"] == $amin[$i]){
                          echo "<option selected value=\"".$amin[$i]."\">".$val[$i]."</option>";
                       } else {
                          echo "<option value=\"".$amin[$i]."\">".$val[$i]."</option>";
                       }
                    }
                    /*
                  <option value ="">-</option>
                  <option  value="0 AND DISCO<=80">   menos de 80 GB</option>
                  <option  value="81 AND DISCO<=120"> entre 81 y 120 GB</option>
                  <option  value="121 AND DISCO<=320">entre 121 y 320 GB</option>
                  <option  value="321 AND DISCO<=500">entre 321 y 500 GB</option>
                  <option  value="501 AND DISCO<=999">entre 501 y 999 GB</option>
                  <option  value="1000">              M&aacute;s de un 1 TB</option>
                     */
                  ?>
                </SELECT></td>
            </tr>
            <tr>
              <td>Pantalla</td>
              <td><select size="1" name="pantalla">
                  <?php if($_GET["pantalla"] == ""){  ?>
                  <option selected value="">Todas</option>
                  <? } else { ?>
                    <option value="">Todas</option>
                  <?php } if($_GET["pantalla"] == "PANTALLA>=8.9 AND PANTALLA<=12.1"){  ?>
                    <option selected value="PANTALLA>=8.9 AND PANTALLA<=12.1">Entre 8.9 y 12.1</option>
                  <?php } else { ?>
                    <option value="PANTALLA>=8.9 AND PANTALLA<=12.1">Entre 8.9 y 12.1</option>
                  <?php } if($_GET["pantalla"] == "PANTALLA>=13.3 AND PANTALLA<=17"){  ?>
                    <option selected  value="PANTALLA>=13.3 AND PANTALLA<=17">Entre 13.3 y 17</option>
                  <?php } else { ?>
                    <option value="PANTALLA>=13.3 AND PANTALLA<=17">Entre 13.3 y 17</option>
                  <?php } ?>
                </select></td>
            </tr>
            <tr>
              <td>
                  <input type="image" src="images/catalogo/bot-buscar-catal.jpg" alt="Buscar">
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div style="margin-top: 5px; margin-bottom: 20px; border: 3px solid #FED443;padding-left: 20px;" id="contenido">
        <font class="Myriad Pro" style="" size="5" color="#EF7100">
          <b><I>Organizar por:</I></b>
        </font>
        <br>
        <br>
        Precio
        <select name="organizar" onchange="document.catalogo.submit();">
          <option value="0">Sin Orden</option>
          <option value="1">De mayor a menor</option>
          <option value="2">De menor a mayor</option>
        </select>
        <br>
        <div style="margin-top: 20px ;font-size: 10px; text-align: right;padding-bottom: 10px; padding-right: 10px;">
        Ver
        <SELECT name="num" >
          <?php opciones_ver($_GET["num"]);?>
        </SELECT> por p&aacute;gina
        <?php
          $f = new fachadaBD();
          $limit = $_GET["num"];
          $total_results = $f->listarTodos($_GET["marca"],$_GET["tipo"],$_GET["min"],$_GET["max"],$_GET["discomin"],$_GET["discomax"],$_GET["precio"],$_GET["pantalla"],$_GET["hdmi"],$_GET["web"],$_GET["procesador"]);
          if($limit != 0){
            $total_pages = ceil($total_results / $limit);//total number of pages
            $page = $_GET["page"];
            if (empty($page)){
              $page = "1"; //default page if none is selected
            }
            $offset = ($page - 1) * $limit; //starting number for displaying results out of DB
            $lista = $f->listarTodoslim($limit, $offset,$_GET["marca"],$_GET["tipo"],$_GET["min"],$_GET["max"],$_GET["discomin"],$_GET["discomax"],$_GET["precio"],$_GET["pantalla"],$_GET["hdmi"],$_GET["web"],$_GET["procesador"],$_GET["organizar"]);
            $aux = $offset + 1;
            $aux2 = $offset + mysql_num_rows($lista);
                  // This is the Previous/Next Navigation
          }
          if($aux2){
            echo "<font face=Verdana size=1>";
            echo "$aux-$aux2 de $total_results &nbsp;&nbsp;"; // total pages
            if ($page != 1){
              echo "<a href=$PHP_SELF?page=1&marca=".$_GET["marca"]."&num=".$_GET["num"]."><< Primera</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
              $prevpage = $page - 1;
              echo "&nbsp;<a href=$PHP_SELF?page=$prevpage&marca=".$_GET["marca"]."&num=".$_GET["num"]."><<</a>&nbsp;"; // Previous Page Link
            }
            if ($page == $total_pages){
              $to = $total_pages;
            }elseif ($page == $total_pages-1){
              $to = $page+1;
            }elseif ($page == $total_pages-2){
              $to = $page+2;
            }else{
              $to = $page+3;
            }
            if ($page == 1 || $page == 2 || $page == 3){
              $from = 1;
            }
            else{
              $from = $page-3;
            }
            for ($i = $from; $i <= $to; $i++){
              if ($i == $total_results) $to=$total_results;
              if ($i != $page){
                echo "<a href=$PHP_SELF?showold=yes&page=$i&marca=".$_GET["marca"]."&num=".$_GET["num"].">$i</a>";
              }else{
                echo "<b><font face=Verdana size=2>[$i]</font></b>";
              }
              if ($i != $total_pages)
                echo "&nbsp;";
            }
            if ($page != $total_pages){
              $nextpage = $page + 1;
              echo "&nbsp;<a href=$PHP_SELF?page=$nextpage&marca=".$_GET["marca"]."&num=".$_GET["num"].">>></a>&nbsp;"; // Next Page Link
              echo "&nbsp;&nbsp;&nbsp;<a href=$PHP_SELF?page=$total_pages&marca=".$_GET["marca"]."&num=".$_GET["num"].">&Uacute;ltima >></a>"; // Last Page Link
            }
            echo "</font>";
          }
        ?>
        </div>
      </div>
    </form>
      <table width=100%>
        <?php
          /** AQUI LE AGREGO LO QUE RECIBE POR PARAMETRO DE LA BARRA DE BUSQUEDA DE TOP ***/
          if ($_POST["busq"]){
            $lista = $f->busqueda($_POST["busq"]);
          }
          if ($lista) {
            while ($row=mysql_fetch_array($lista) ) {
              echo "<tr><td>";
              $marcaTec =  $f->getMarcaTecno($row["PROCESADOR"]);
              div($row,$marcaTec);
              echo "</td></tr>";
              echo "</tr>";
              echo "<tr><td COLSPAN=3><br></td></tr>";
        //          echo "<tr bgcolor = \"#F0F0F0\"><td COLSPAN=3><br></td></tr>";
            }
          }
        ?>
      </table>
        <div style="margin-bottom: 20px; text-align: center; padding: 5px; margin-left: 60px;">
        <?
          /* Aqui agregamos el indicador de la pagina en la que estoy y cuantas paginas faltan
           * para navegar en la busqueda.
           */
          $total_results = $f->listarTodos($_GET["marca"],$_GET["tipo"],$_GET["min"],$_GET["max"],$_GET["discomin"],$_GET["discomax"],$_GET["precio"],$_GET["pantalla"],$_GET["hdmi"],$_GET["web"],$_GET["procesador"]);
          if($limit != 0){
            $total_pages = ceil($total_results / $limit);//total number of pages
            $page = $_GET["page"];
            if (empty($page)){
              $page = "1"; //default page if none is selected
            }
            $offset = ($page - 1) * $limit; //starting number for displaying results out of DB
            $lista = $f->listarTodoslim($limit, $offset,$_GET["marca"],$_GET["tipo"],$_GET["min"],$_GET["max"],$_GET["discomin"],$_GET["discomax"],$_GET["precio"],$_GET["pantalla"],$_GET["hdmi"],$_GET["web"],$_GET["procesador"],$_GET["organizar"]);
            $aux = $offset + 1;
            $aux2 = $offset + mysql_num_rows($lista);
                  // This is the Previous/Next Navigation
          }
          if($aux2){
            echo "<font face=Verdana size=1>";
            echo "$aux-$aux2 de $total_results &nbsp;&nbsp;"; // total pages
            if ($page != 1){
              echo "<a href=$PHP_SELF?page=1&marca=".$_GET["marca"]."&num=".$_GET["num"]."><< Primera</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
              $prevpage = $page - 1;
              echo "&nbsp;<a href=$PHP_SELF?page=$prevpage&marca=".$_GET["marca"]."&num=".$_GET["num"]."><<</a>&nbsp;"; // Previous Page Link
            }
            if ($page == $total_pages){
              $to = $total_pages;
            }elseif ($page == $total_pages-1){
              $to = $page+1;
            }elseif ($page == $total_pages-2){
              $to = $page+2;
            }else{
              $to = $page+3;
            }
            if ($page == 1 || $page == 2 || $page == 3){
              $from = 1;
            }
            else{
              $from = $page-3;
            }
            for ($i = $from; $i <= $to; $i++){
              if ($i == $total_results) $to=$total_results;
              if ($i != $page){
                echo "<a href=$PHP_SELF?showold=yes&page=$i&marca=".$_GET["marca"]."&num=".$_GET["num"].">$i</a>";
              }else{
                echo "<b><font face=Verdana size=2>[$i]</font></b>";
              }
              if ($i != $total_pages)
                echo "&nbsp;";
            }
            if ($page != $total_pages){
              $nextpage = $page + 1;
              echo "&nbsp;<a href=$PHP_SELF?page=$nextpage&marca=".$_GET["marca"]."&num=".$_GET["num"].">>></a>&nbsp;"; // Next Page Link
              echo "&nbsp;&nbsp;&nbsp;<a href=$PHP_SELF?page=$total_pages&marca=".$_GET["marca"]."&num=".$_GET["num"].">&Uacute;ltima >></a>"; // Last Page Link
            }
            echo "</font>";
          }
          $f->cerrar();
        ?>
        </div>
    </div>
  </div>
    <?php
      include("low.php");
    ?>
  </body>
</html>
